using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsGame1
{
    public class LineList : DrawableGameComponent
    {
        // a basic effect, which contains the shaders that we will use to draw our
        // primitives.
        BasicEffect basicEffect;

        // an array of the vertices that have to be drawn
        VertexPositionColor[] vertices;

        // the vertex declaration that will be set on the device for drawing. this is 
        // created automatically using VertexPositionColor's vertex elements.
        VertexDeclaration vertexDeclaration;

        public LineList(Game game)
            : base(game) { }

        public void LoadContent(GraphicsDevice currentGraphicsDevice)
        {
            // set up a new basic effect, and enable vertex colors.
            basicEffect = new BasicEffect(currentGraphicsDevice, null);
            basicEffect.VertexColorEnabled = true;

            // projection uses CreateOrthographicOffCenter to create 2d projection
            // matrix with 0,0 in the upper left.
            basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0, currentGraphicsDevice.Viewport.Width,
                currentGraphicsDevice.Viewport.Height, 0,
                0, 1);

            // create a vertex declaration, which tells the graphics card what kind of
            // data to expect during a draw call. We're drawing using
            // VertexPositionColors, so we'll use those vertex elements.
            vertexDeclaration = new VertexDeclaration(currentGraphicsDevice, VertexPositionColor.VertexElements);
        }

        public void Draw(GraphicsDevice currentGraphicsDevice)
        {
            
            // prepare the graphics device for drawing by setting the vertex declaration
            currentGraphicsDevice.VertexDeclaration = vertexDeclaration;
            // tell our basic effect to begin.
            basicEffect.Begin();
            basicEffect.CurrentTechnique.Passes[0].Begin();

            currentGraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, vertices.Length/2);

            // tell basic effect that we're done.
            basicEffect.CurrentTechnique.Passes[0].End();
            basicEffect.End();

            
        }

        public VertexPositionColor[] Vertices
        {
            get
            {
                return vertices;
            }
            set
            {
                vertices = value;
            }
        }
    }
}
